package com.shensi.adminCollect.controller.market;

import com.shensi.common.core.controller.BaseController;
import com.shensi.common.core.domain.ResultData;
import com.shensi.common.core.page.TableDataInfo;
import com.shensi.adminCollect.domain.markert.req.SaleActivityQueryReq;
import com.shensi.adminCollect.domain.markert.vo.SaleActivityVO;
import com.shensi.adminCollect.service.markert.ISaleActivityService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @description sale_activity
 * @date 2023-12-20
 */
@RestController
@RequestMapping(value = "/saleActivity")
public class SaleActivityController extends BaseController {

    @Resource
    private ISaleActivityService saleActivityService;

    /**
     * 刪除
     * @date 2023/12/20
     **/
    @GetMapping("/delete")
    public ResultData delete(Long[] ids){
        saleActivityService.removeByIds(Arrays.asList(ids));
        return ResultData.success();
    }

    /**
     * 更新
     * @date 2023/12/20
     **/
    @PostMapping("/save")
    public ResultData save(@RequestBody SaleActivityVO saleActivityVO){
        saleActivityService.insertOrUpdate(saleActivityVO);
        return ResultData.success();
    }

    /**
     * 查询 根据主键 id 查询
     * @date 2023/12/20
     **/
    @GetMapping("/getById")
    public ResultData<SaleActivityVO> getById(@RequestParam Long id){
        return ResultData.success(saleActivityService.getSaleActivityVOById(id));
    }

    /**
     * 查询 分页查询
     * @date 2023/12/20
     **/
    @GetMapping("/list")
    public TableDataInfo list(SaleActivityQueryReq queryReq){
        startPage();
        return getDataTable(saleActivityService.queryList(queryReq));
    }

    @GetMapping("enable/{id}")
    public ResultData switchEnable(@PathVariable Long id){
        saleActivityService.switchEnable(id);
        return ResultData.success();
    }
}
